package com.tencet.servlet;

import com.tencet.service.Impl.AccountOneServiceImpl;
import com.tencet.service.Impl.AccountTwoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;

/**
 * @author Yangjx
 * @version 1.0.0
 * @ClassName SubscriptionCardServlet.java
 * @Description TODO
 * @createTime 2022年07月22日 09:59
 */
@WebServlet("/subscriptioncard.servlet")
public class SubscriptionCardServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //绑卡界面的输入信息
        String name = req.getParameter("name");
        String card_num = req.getParameter("card_num");
        String phone = req.getParameter("phone");
        String payPassword = req.getParameter("payPassword");
        //从session中获取开户存放的二类账户号
        String secondAccountNumber = (String) req.getSession().getAttribute("secondAccountNumber");
        //用二类账户号查询openaccount表中的uuid,用于一、二类卡关系的绑定
        AccountTwoServiceImpl accountTwoService = new AccountTwoServiceImpl();
        String id = accountTwoService.getId(secondAccountNumber);
        //将uuid、一类卡号、二类卡信息存入bank_account1,形成绑卡关系，返回影响行数
        AccountOneServiceImpl accountOneService = new AccountOneServiceImpl();
        int i = accountOneService.addCard(UUID.randomUUID() + "", card_num, id);
        //对绑卡结果进行判断，返回结果给前端
        if (i>0) {
            resp.getWriter().print("y");
        } else {
            resp.getWriter().print("n");
        }
    }


}
